package com.dodoke.system.service.impl;

import java.util.List;

import com.dodoke.common.core.domain.entity.SysWechatUserDO;
import com.dodoke.common.utils.DateUtils;
import com.dodoke.common.utils.uuid.IdUtils;
import com.dodoke.system.domain.SysWechatUserRoleDO;
import com.dodoke.system.mapper.SysWechatUserMapper;
import com.dodoke.system.mapper.SysWechatUserRoleMapper;
import com.dodoke.system.service.ISysWechatUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 微信小程序用户Service业务层处理
 * 
 * @author ezreal_geng
 * @date 2020-08-27
 */
@Service
public class SysWechatUserServiceImpl implements ISysWechatUserService {
    @Autowired
    private SysWechatUserMapper sysWechatUserMapper;

    @Autowired
    private SysWechatUserRoleMapper sysWechatUserRoleMapper;

    /**
     * 查询微信小程序用户
     * 
     * @param id 微信小程序用户ID
     * @return 微信小程序用户
     */
    @Override
    public SysWechatUserDO selectSysWechatUserById(Long id) {
        return sysWechatUserMapper.selectSysWechatUserById(id);
    }


    /**
     * 查询微信小程序用户
     *
     * @param openId 微信小程序用户openId
     * @return 微信小程序用户
     */
    @Override
    public SysWechatUserDO selectSysWechatUserByOpenId(String openId) {
        return sysWechatUserMapper.selectSysWechatUserByOpenId(openId);
    }

    /**
     * 查询微信小程序用户列表
     * 
     * @param sysWechatUserDo 微信小程序用户
     * @return 微信小程序用户
     */
    @Override
    public List<SysWechatUserDO> selectSysWechatUserList(SysWechatUserDO sysWechatUserDo) {
        return sysWechatUserMapper.selectSysWechatUserList(sysWechatUserDo);
    }

    /**
     * 新增微信小程序用户
     * 
     * @param sysWechatUserDo 微信小程序用户
     * @return 结果
     */
    @Override
    public int insertSysWechatUser(SysWechatUserDO sysWechatUserDo) {
        sysWechatUserDo.setId(IdUtils.fastSimpleUUID());
        sysWechatUserDo.setCreateTime(DateUtils.getNowDate());
        sysWechatUserMapper.insertSysWechatUser(sysWechatUserDo);

        SysWechatUserRoleDO wechatUserRole = new SysWechatUserRoleDO();
        wechatUserRole.setWechatUserId(sysWechatUserDo.getId());
        // 默认微信小程序角色
        wechatUserRole.setRoleId(Long.parseLong("100"));

        return sysWechatUserRoleMapper.insertSysWechatUserRole(wechatUserRole);
    }

    /**
     * 修改微信小程序用户
     * 
     * @param sysWechatUserDo 微信小程序用户
     * @return 结果
     */
    @Override
    public int updateSysWechatUser(SysWechatUserDO sysWechatUserDo) {
        sysWechatUserDo.setUpdateTime(DateUtils.getNowDate());
        return sysWechatUserMapper.updateSysWechatUser(sysWechatUserDo);
    }

    /**
     * 批量删除微信小程序用户
     * 
     * @param ids 需要删除的微信小程序用户ID
     * @return 结果
     */
    @Override
    public int deleteSysWechatUserByIds(Long[] ids) {
        return sysWechatUserMapper.deleteSysWechatUserByIds(ids);
    }

    /**
     * 删除微信小程序用户信息
     * 
     * @param id 微信小程序用户ID
     * @return 结果
     */
    @Override
    public int deleteSysWechatUserById(Long id) {
        return sysWechatUserMapper.deleteSysWechatUserById(id);
    }
}
